/** @file
* Use 4 keys simulation mouse move
*
* @author Ivan HE
*
*/
#include "mousepad.h"



/*******************************************************************************
* Function Name : Joystick_Send.
* Description   : prepares buffer to be sent containing Joystick event infos.
* Input         : Keys: keys received from terminal.
* Output        : None.
* Return value  : None.
*******************************************************************************/

void Joystick_Send(uint8_t Keys)
{
	uint8_t Mouse_Buffer[4] = {0,0,0,0};
	int8_t	X = 0, Y = 0;

	switch (Keys) {
		case LEFT:
			X -= CURSOR_STEP;
			break;
		case RIGHT:
			X += CURSOR_STEP;
			break;
		
		case UP:
			Y -= CURSOR_STEP;
			break;
		
		case DOWN:
			Y += CURSOR_STEP;
			break;
		default:
			return;
	}

	//prepare buffer to send
	Mouse_Buffer[1] = X;
	Mouse_Buffer[2] = Y;

	usb_send_packet
		(
			Mouse_Buffer,
			USB_EP_MOUSE,
			(APP_MOUSE_PL_LENGTH - APP_DATA)
		 );


}

/*******************************************************************************
* Function Name : JoyState.
* Description   : Decodes the Joystick direction.
* Input         : None.
* Output        : None.
* Return value  : The direction value.
*******************************************************************************/
uint8_t JoyState(void)
{
	/* "right" key is pressed */
	if (!JOY_RIGHT)
	{
	  return RIGHT;
	}
	/* "left" key is pressed */
	if (!JOY_LEFT)
	{
	
	  return LEFT;
	}
	/* "up" key is pressed */
	if (!JOY_UP)
	{
	  
	  return UP;
	}
	/* "down" key is pressed */
	if (!JOY_DOWN)
	{
	  
	  return DOWN;
	}
	/* No key is pressed */
	else
	{
	  return 0;
	}

}

